#!/usr/bin/bash

# echo $#

if [ "$#" != "1" ]; then
    echo "please give a string as argument"
    exit
fi

export PATH=$PATH:/mingw64/bin

echo -ne '\e]0;ATypingBot\a'

this_pid=$$
text=$1
#trans_text=$(./trans -e google -s en -t zh -brief "${text}")
source $HOME/virtualenv/ollama/bin/activate
trans_text=$(python ollama_tran.py "${text}")

# audio="$(<kb_snd2.wav)"

# ./AutoHotkey64.exe increase_mintty_fontsize.ahk
reset

(
    mpg123 --loop -1 -q kb_snd2.mp3
    #while true; do
        #    cat morse_code1.wav | nc -N 127.0.0.1 3399
        # cat kb_snd2.wav > /dev/dsp
    #done
    
    # ( echo "$audio"; cat - ) > /dev/dsp

) &
audio_pid=$!

(
    printf "\n\n\n\n\n"
    printf "___\033[37;42m${text^^}\033[0m___" | pv -qL 10
    printf "\r\n"
    printf "___\033[0;30;43m${trans_text}\033[0m___\n"  | pv -qL 10
    kill -9 $audio_pid
) &
text_pid=$!

wait $audio_pid > /dev/null 2>&1
wait $text_pid > /dev/null 2>&1

sleep 2

./imgcat cat.png
# ./AutoHotkey64.exe reset_mintty_fontsize.ahk

# reset
